|
|
|
|
|
|
|
This suggests that one or both of the parameters is not correct and raises two interesting questions: |
|
|
|
|
|
|
|
|
1. Why does this function return a LastError value of 123 on Windows NT, implying some sort of parameter error, and 0 on Windows 95/98? |
|
|
|
|
|
|
|
|
2. Does the fact that FindWindow is returning a LastError value on NT suggest that there is a real problem with one of the parameters, or is it just that a window couldn't be found? |
|
|
|
|
|
|
|
|
Figure S2-1:
Passing vbNullString and empty strings as parameters |
|
|
|
|
|
|
|
|
It pays to take a closer look at the parameters in case there is a real problem. The window caption parameter type is correct, but make sure that the contents of the text box correspond to a window caption. |
|
|
|
|
|
|
|
|
Which leaves the class name. The documentation for the function suggests that the class name parameter is ignored if you pass NULL. |
|
|
|
|
|
|
|
|
But what exactly does NULL mean? |
|
|
|
|
|
|
|
|
NULL in C++ terms always means 0specifically, that the value 0 can be found on the stack for that parameter.1 In the sample program, we're passing ''" as the class name. Is this NULL? |
|
|
|
|
|
|
|
|
No, "" is an empty string. In C terms, "" means a pointer to the terminating NULL character of a string. So, in this case, it means that a pointer will be passed as a parameter, and that pointer will appear on the stack. That is not the same thing as NULL, as shown in Figure S2-1. |
|
|
|
|
|
|
|
|
Fortunately, Visual Basic provides an easy wayby using the constant vbNullStringto pass a NULL value when a parameter is declared as a string. |
|
|
|
|
|
|
|
|
Figure S2-1 shows the contents of the lpClassName parameter on the stack when an empty string ("") and |
|
|
|
 |
|
 |
|
|
1 You'll find information on stacks and stack frames in Tutorial 4, "How DLL Calls Work: Inside a Stack Frame," in Part III of this book. |
|
|
|
|
|